# -*- coding:utf-8 -*-

"""
为什么前后不分离使用resutful风格不好
    1. 由于对单个操作的的时候通常是 更新，删除，查看单个同一条链接


"""

from django.urls import re_path, path
from rest_framework.urlpatterns import format_suffix_patterns
from rest_framework_jwt.views import obtain_jwt_token
from django.conf import settings
# namespace
app_name = 'blog'

from .views import view_v4, view_v5

from django.conf.urls.static import static
from rest_framework_simplejwt.views import (
    TokenObtainPairView,  # 获取token
    TokenRefreshView,  # token 刷新
)

##############建议使用v3和v4


########使用视图集ViewSet#########
from rest_framework.routers import DefaultRouter

router = DefaultRouter()
router.register(r'articles', viewset=view_v5.ArticleViewSet)
########使用视图集ViewSet#########

urlpatterns = [
    # ###############通过视图函数实现resutful################
    # re_path(r'^articles/$', views_v1.article_list),
    # re_path(r'^articles/(?P<pk>[0-9]+)$', views_v1.article_detail),

    # ###############通过APIView实现resutful################
    # re_path(r'^articles/$', views_v2.ArticleList.as_view()),
    # re_path(r'^articles/(?P<pk>[0-9]+)$', views_v2.ArticleDetail.as_view()),

    # ###############通过GenericAPIView实现resutful################
    # re_path(r'^articles/$', views_v3.ArticleList.as_view()),
    # re_path(r'^articles/(?P<pk>[0-9]+)$', views_v3.ArticleDetail.as_view()),
    # # 这里的参数命名只能是pk, 可以修改GenericAPIView中的 lookup_field 属性

    ##############通过使用通用视图Generics.*类实现resutful################
    re_path(r'^articles/$', view_v4.ArticleList.as_view()),
    re_path(r'^articles/(?P<pk>[0-9]+)$', view_v4.ArticleDetail.as_view()),

    re_path(r'^users/$', view_v4.UserList.as_view()),
    re_path(r'^users/(?P<pk>[0-9]+)$', view_v4.UserDetail.as_view()),

    re_path(r'^profles/$', view_v4.ProfileList.as_view()),
    re_path(r'^profles/(?P<pk>[0-9]+)$', view_v4.ProfileDetail.as_view()),

    re_path(r'^login/$', obtain_jwt_token),

    path('token/', TokenObtainPairView.as_view(), name='token_obtain_pair'),
    path('token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),

    # 这里的参数命名只能是pk, 可以修改GenericAPIView中的 lookup_field  类属性

    ###############通过使用视图集ViewSet实现resutful################

]


if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

urlpatterns = format_suffix_patterns(urlpatterns)  # 允许通过后缀 .api .json来设置显示内容
#
# ########使用视图集ViewSet#########
# urlpatterns += router.urls
########使用视图集ViewSet#########
